package com.ydw.blog.config;

import com.ydw.blog.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyWebConfiguration implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/blog").setViewName("blog");
        registry.addViewController("/tags").setViewName("tags");
        registry.addViewController("/types").setViewName("types");
        registry.addViewController("/about").setViewName("about");
        registry.addViewController("/archives").setViewName("archives");
        registry.addViewController("/admin/blogs").setViewName("admin/blogs");
        registry.addViewController("/admin/index").setViewName("admin/index");
        registry.addViewController("/admin/input").setViewName("admin/blogs-input");
        registry.addViewController("/admin/types").setViewName("admin/types");
        registry.addViewController("/admin/typeinput").setViewName("admin/type-input");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/admin/**")
                .excludePathPatterns("/admin/")
                .excludePathPatterns("/admin/login");
    }
}
